// package e4tingclient
package main

import (
	"fmt"
	"context"
	"e4ting/e4tingclient"
	"github.com/zeromicro/go-zero/zrpc"

	"github.com/alecthomas/kingpin/v2"
)

var url = kingpin.Flag("url", "对端地址").Default("127.0.0.1:8080").Envar("URL").String()

func init(){
	kingpin.Version("1.0.1").VersionFlag.Short('v')
	kingpin.Parse()
}

func main() {
	// client, err := zrpc.NewClientWithTarget("api.e4ting.cn:8080")

	client, err := zrpc.NewClientWithTarget(*url)
	if err != nil {
		fmt.Println("Failed to create client:", err)
		return
	}
	// defer client.Close()

	cli := e4tingclient.NewE4ting(client)

	data0,_ := cli.NewType(context.Background(), &e4tingclient.NewTypeReq{Name: "总计", Detail: "统计类型"})
	fmt.Println(data0.Code)

	data0,_ = cli.NewType(context.Background(), &e4tingclient.NewTypeReq{Name: "人民币", Detail: "软妹币"})
	fmt.Println(data0.Code)

	data0,_ = cli.NewType(context.Background(), &e4tingclient.NewTypeReq{Name: "美元", Detail: "刀乐"})
	fmt.Println(data0.Code)

	data1,_ := cli.ListType(context.Background(), &e4tingclient.SearchRequest{Page: 1, Size: 10})
	// fmt.Println(data1.Total)
	fmt.Println(data1.Data)

	data2,_ := cli.GetType(context.Background(), &e4tingclient.ID{Name:"人民币"})
	fmt.Println(data2.Data)

	data3,_ := cli.NewAccount(context.Background(), &e4tingclient.NewAccountReq{Name: "狍子", Uuid:"e4ting", Detail: "软妹币", TypeID: data2.Data.Id})
	fmt.Println(data3.Code)

	data3,_ = cli.NewAccount(context.Background(), &e4tingclient.NewAccountReq{Name: "测试", Uuid:"test", Detail: "测试币", TypeID: data2.Data.Id})
	fmt.Println(data3.Code)

	data4,_ := cli.ListAccount(context.Background(), &e4tingclient.SearchRequest{Page: 1, Size: 10})
	fmt.Println(data4.Data)

	data41,_ := cli.GetAccount(context.Background(), &e4tingclient.ID{Name:"狍子"})
	fmt.Println(data41.Data)

	data5,_ := cli.AccountIn(context.Background(), &e4tingclient.BillingReq{AccountID: data41.Data.Id, Money: 10, Detail: "入账测试"})
	fmt.Println(data5)

	data5,_ = cli.AccountIn(context.Background(), &e4tingclient.BillingReq{AccountID: data41.Data.Id, Money: 100, Detail: "入账测试"})
	fmt.Println(data5)

	data5,_ = cli.AccountOut(context.Background(), &e4tingclient.BillingReq{AccountID: data41.Data.Id, Money: 50, Detail: "出账测试"})
	fmt.Println(data5)

	data5,_ = cli.AccountOut(context.Background(), &e4tingclient.BillingReq{AccountID: data41.Data.Id, Money: 1000, Detail: "出账测试"})
	fmt.Println(data5)

	data6,_ := cli.GetUTXO(context.Background(), &e4tingclient.ListReq{AccountID: data41.Data.Id, Search:&e4tingclient.SearchRequest{Page: 1, Size: 10}})
	fmt.Println(data6.Total, len(data6.Data))
	fmt.Println(data6.Data)

}